"""定义与废料相关的模型类的文件."""
from datetime import datetime
from typing import List

from fastapi import Body
from pydantic import BaseModel, field_validator

from lib.html_sanitizer import content_sanitizer as sanitizer
from api.v1.models.pagination import PaginationResponse


class ScrapBoardResponse(BaseModel):
    """报废页公告板信息模型"""
    bo_table: str
    bo_subject: str


class ScrapWriteResponse(BaseModel):
    """报废页书写信息模型"""
    wr_id: int
    wr_subject: str


class ScrapFormResponse(BaseModel):
    """报废登记页面设置响应模型"""
    board: ScrapBoardResponse
    write: ScrapWriteResponse


class CreateScrap(BaseModel):
    """剪切创建模型"""
    wr_content: str = Body(
        default="",
        title="评论",
        description="剪报时要添加的评论内容"
    )

    @field_validator('wr_content', mode='after')
    @classmethod
    def sanitize_wr_content(cls, v: str):
        """评论内容 Stored XSS 反滤波"""
        return sanitizer.get_cleaned_data(v)


class ScrapResponse(BaseModel):
    """报废响应模型"""
    ms_id: int
    mb_id: str
    bo_table: str
    wr_id: int
    ms_datetime: datetime

    wr_subject: str
    bo_subject: str


class ScrapListResponse(PaginationResponse):
    """废品清单响应模型"""
    scraps: List[ScrapResponse]
